package com.yike.user.controller;

import com.yike.common.api.Add;
import com.yike.common.api.ApiResult;
import com.yike.common.api.Update;
import com.yike.common.base.BaseController;
import com.yike.common.enums.OperationLogType;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.pagination.Paging;
import com.yike.user.param.PlatformAgentPageParam;
import com.yike.user.param.PlatformAgentParam;
import com.yike.user.service.PlatformAgentService;
import com.yike.user.vo.PlatformAgentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台客户 控制器
 *
 * @author Sakura
 * @since 2024-10-31
 */
@Slf4j
@RestController
@RequestMapping("/platform/agent")
@Module("user")
@Api(value = "平台代理商API", tags = {"平台代理商管理"})
public class PlatformAgentController extends BaseController {

    @Autowired
    private PlatformAgentService platformAgentService;

    /**
     * 添加代理商
     */
    @PostMapping("/add")
    @OperationLog(name = "添加代理商", type = OperationLogType.ADD)
    @ApiOperation(value = "添加代理商", response = ApiResult.class)
    public ApiResult<Boolean> addAgent(@Validated(Add.class) @RequestBody PlatformAgentParam platformAgentParam) throws Exception {
        boolean flag = platformAgentService.addAgent(platformAgentParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改代理商
     */
    @PostMapping("/update")
    @OperationLog(name = "修改代理商", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改代理商", response = ApiResult.class)
    public ApiResult<Boolean> updateAgent(@Validated(Update.class) @RequestBody PlatformAgentParam platformAgentParam) throws Exception {
        boolean flag = platformAgentService.updateAgent(platformAgentParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除代理商
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除代理商", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除代理商", response = ApiResult.class)
    public ApiResult<Boolean> deleteAgent(@PathVariable("id") Long id) throws Exception {
        boolean flag = platformAgentService.deleteAgent(id);
        return ApiResult.result(flag);
    }

    @PostMapping("/batchDel")
    @OperationLog(name = "批量删除代理商", type = OperationLogType.UPDATE)
    @ApiOperation(value = "批量删除代理商", response = ApiResult.class)
    public ApiResult<Boolean> batchDel(@Validated(Update.class) @RequestBody List<Long> ids) throws Exception {
        boolean flag = platformAgentService.batchDel(ids);
        return ApiResult.result(flag);
    }

    /**
     * 代理商详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "代理商详情", type = OperationLogType.INFO)
    @ApiOperation(value = "代理商详情", response = PlatformAgentVo.class)
    public ApiResult<PlatformAgentVo> getAgent(@PathVariable("id") Long id) throws Exception {
        PlatformAgentVo platformAgentVo = platformAgentService.getAgent(id);
        return ApiResult.ok(platformAgentVo);
    }

    @PostMapping("/getPageList")
    //@OperationLog(name = "代理商分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "代理商分页列表", response = PlatformAgentVo.class)
    public ApiResult<Paging<PlatformAgentVo>> getAgentPageList(@Validated @RequestBody PlatformAgentPageParam platformAgentPageParam) throws Exception {
        Paging<PlatformAgentVo> paging = platformAgentService.getAgentPageList(platformAgentPageParam);
        return ApiResult.ok(paging);
    }


}

